<?php

use yii\widgets\LinkPager;
use common\helpers\Url;
use common\helpers\Html;
use yii\widgets\ActiveForm;

$this->title = '产品管理';
$this->params['breadcrumbs'][] = ['label' => $this->title];
?>

<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?= $this->title; ?></h3>
                <div class="box-tools">
                    <?= Html::create(['ajax-edit'], '创建', [
                        'data-toggle' => 'modal',
                        'data-target' => '#ajaxModalLg',
                    ]) ?>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-10">
                    <?php $form = ActiveForm::begin([
                        'action' => Url::to(['index']),
                        'method' => 'get',
                    ]); ?>
                    <div class="col-sm-3">
                        <div class="input-group m-b">
                            <?= Html::dropDownList('type', null, $cateDropDownList, [
                                'class' => 'form-control',
                                'prompt' => '请选择产品分类',
                                'options' => [$type => ['selected' => true]]
                            ]); ?>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="input-group m-b">
                            <input type="text" class="form-control" name="name" placeholder="产品名称"
                                   value="<?= $name ?>"/>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="input-group m-b">
                            <input type="text" class="form-control" name="code" placeholder="产品代码"
                                   value="<?= $code ?>"/>
                            <span class="input-group-btn"><button class="btn btn-white"><i class="fa fa-search"></i> 搜索</button></span>
                        </div>
                    </div>
                    <?php ActiveForm::end(); ?>
                </div>
            </div>
            <div class="box-body table-responsive">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>产品代码</th>
                        <th>产品名称</th>
                        <th>滑点</th>
                        <th>风控</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($models as $key => $model) { ?>
                        <tr id= <?= $model->code; ?>>
                            <td><?= $key + 1; ?></td>
                            <td><?= $model->code; ?></td>
                            <td><?= $model->name; ?></td>
                            <td><?= $model->risk; ?></td>
                            <td><?php if ($model->risk_auto == 0):echo '未开启自动风控'; else: echo '已开启自动风控'; endif; ?></td>
                            <td>
                                <?= Html::edit(['set-risk', 'id' => $model->id], '设置滑点', [
                                    'data-toggle' => 'modal',
                                    'data-target' => '#ajaxModalLg',
                                ]); ?>
                                <?php if ($model->risk_auto == 0): ?>
                                    <?= Html::edit(['risk-auto', 'id' => $model->id], '开启风控', [
                                        'class' => 'btn btn-success btn-sm'
                                    ]); ?>
                                <?php else: ?>
                                    <?= Html::edit(['risk-auto', 'id' => $model->id], '关闭风控', [
                                        'class' => 'btn btn-danger btn-sm'
                                    ]); ?>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php } ?>
                    </tbody>
                </table>
            </div>
            <div class="box-footer">
                <?= LinkPager::widget([
                    'pagination' => $pages,
                ]); ?>
            </div>
        </div>
    </div>
</div>